﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RobotTracking.CApRTRobotTrackingAttachmentPair
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.RobotTracking;

internal class CApRTRobotTrackingAttachmentPair
{
  private ITxLocatableObject m_objectToAttach;
  private ITxLocatableObject m_attachmentParentCandidate;

  internal CApRTRobotTrackingAttachmentPair(
    ITxLocatableObject objectToAttach,
    ITxLocatableObject attachmentParentCandidate)
  {
    this.m_objectToAttach = objectToAttach;
    this.m_attachmentParentCandidate = attachmentParentCandidate;
  }

  internal ITxLocatableObject ObjectToAttach => this.m_objectToAttach;

  internal ITxLocatableObject AttachmentParentCandidate => this.m_attachmentParentCandidate;

  internal bool NeedToAttach()
  {
    bool attach = false;
    if (this.m_objectToAttach != null && this.m_attachmentParentCandidate != null)
      attach = !this.IsAttached();
    return attach;
  }

  internal bool IsAttached()
  {
    bool flag = false;
    try
    {
      if (this.m_objectToAttach == null || this.m_attachmentParentCandidate == null || this.m_attachmentParentCandidate != this.m_objectToAttach.AttachmentParent)
      {
        if (this.m_attachmentParentCandidate != TxEngineeringDataInternal.GetScope((ITxObject) this.m_objectToAttach))
          goto label_5;
      }
      flag = true;
    }
    catch (Exception ex)
    {
      flag = false;
    }
label_5:
    return flag;
  }

  internal bool TryAttach()
  {
    bool flag = false;
    try
    {
      if (this.m_objectToAttach != null)
      {
        if (this.m_attachmentParentCandidate != null)
        {
          if (this.m_objectToAttach.CanAttachTo(this.m_attachmentParentCandidate))
            this.m_objectToAttach.AttachTo(this.m_attachmentParentCandidate);
          flag = this.IsAttached();
        }
      }
    }
    catch (Exception ex)
    {
      flag = false;
    }
    return flag;
  }
}
